function executeJs() {
    var qingteng = {

        encodeUTF8:function (s){
            var i, r = [], c, x;
            for (i = 0; i < s.length; i++)
                if ((c = s.charCodeAt(i)) < 0x80) r.push(c);
                else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
                else {
                    if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
                        c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
                            r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
                    else r.push(0xE0 + (c >> 12 & 0xF));
                    r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
                }
            ;
            return r;
        },

        // 字符串加密成 hex 字符串
        sha1:function (str) {
            var data = new Uint8Array(this.encodeUTF8(str))
            var i, j, t;
            var l = ((data.length + 8) >>> 6 << 4) + 16, s = new Uint8Array(l << 2);
            s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
            for (t = new DataView(s.buffer), i = 0; i < l; i++) s[i] = t.getUint32(i << 2);
            s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
            s[l - 1] = data.length << 3;
            var w = [], f = [
                    function () {
                        return m[1] & m[2] | ~m[1] & m[3];
                    },
                    function () {
                        return m[1] ^ m[2] ^ m[3];
                    },
                    function () {
                        return m[1] & m[2] | m[1] & m[3] | m[2] & m[3];
                    },
                    function () {
                        return m[1] ^ m[2] ^ m[3];
                    }
                ], rol = function (n, c) {
                    return n << c | n >>> (32 - c);
                },
                k = [1518500249, 1859775393, -1894007588, -899497514],
                m = [1732584193, -271733879, null, null, -1009589776];
            m[2] = ~m[0], m[3] = ~m[1];
            for (i = 0; i < s.length; i += 16) {
                var o = m.slice(0);
                for (j = 0; j < 80; j++)
                    w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
                        t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
                        m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
                for (j = 0; j < 5; j++) m[j] = m[j] + o[j] | 0;
            }
            ;
            t = new DataView(new Uint32Array(m).buffer);
            for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2);

            var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
                return (e < 16 ? "0" : "") + e.toString(16);
            }).join("");
            return hex;
        },

        // 上面是 sha-1 加密算法

        params: {},
        data: {},
        timestamp:0, //时间戳
        access_token: '',
        sign:"", //签名信息
        hots:["win","linux"],
        resultData:[],

        setParams: function (params) {
            if (typeof params !== 'object') {
                return;
            }
            this.params = params;
        },
        checkHttps:function (requestUrl,request){
            if (requestUrl.startsWith('https://')) {
                request.enableHttps();
            }
        },

        getToken:function (){
            var resultStr, requestUrl = this.params.tokenUrl, request = $CurlHttpRequest;
            this.checkHttps(requestUrl, request);

            var body =  JSON.stringify({
                "username":this.params.username,
                "password":this.params.password
            })

            resultStr = request.post(requestUrl, body);
            var result = JSON.parse(resultStr);

            if (result.success){
                this.data = result.data
                $ScriptLog.Log(1, '获取到青藤云 token 数据 '+ this.data.jwt);

            }else {
                return $Result.error("获取青藤云token认证失败" +result.message)
            }

        },
        signature:function (){
            this.timestamp = Date.now()
            var jointSign = this.data + this.timestamp + this.signKey;

            // 生成签名
            this.sign = this.sha1(jointSign);
            $ScriptLog.Log(2, '根据token 生成key签名 '+ this.sign );
        },

        getHostCountData:function (){
            var countArray = [];
            var resultStr, requestUrl = this.params.hostUrl, request = $CurlHttpRequest;
            request.addHeader('Content-Type', 'application/json');
            request.addHeader('comId', this.data.comId);
            request.addHeader('sign', this.sign);
            request.addHeader('timestamp', this.timestamp);
            request.addHeader('Authorization', "Bearer "+ this.data.jwt);
            this.hots.forEach(function (item) {

                resultStr = request.get(requestUrl+"/"+item);

                if (!resultStr) {
                    $ScriptLog.Log(3, '未获得数据' + requestUrl+"/"+item);
                }
                var result = JSON.parse(resultStr);
                $ScriptLog.Log(4, '解析获得的数据 result ');
                countArray.push({
                    name: item + "设备数量",
                    value: result.total
                })
                $ScriptLog.Log(5, '拼装数据countArray' + JSON.stringify(countArray));
            });
            var countHosts =  {
                title: "WIN/LINUX\\n服务器数量",
                data: countArray
            }
            $ScriptLog.Log(6, '拼装数据countHosts' + JSON.stringify(countHosts));
            // 调用数据库查询
            return this.getDBCountData(countHosts);
        },
        getDBCountData:function (countHosts){
            var countDBArray = [];
            var dbArray = [];
            var userCount = {};
            //这里url 需要修改
            var resultStr, requestUrl = this.params.dbUrl, request = $CurlHttpRequest;
            request.addHeader('Content-Type', 'application/json');
            request.addHeader('comId', this.data.comId);
            request.addHeader('sign', this.sign);
            request.addHeader('timestamp', this.timestamp);
            request.addHeader('Authorization', "Bearer "+ this.data.jwt);
            $ScriptLog.Log(7, '数据数据库url' + requestUrl);
            this.hots.forEach(function (item) {

                resultStr = request.get(requestUrl+"/"+item);
                var result = JSON.parse(resultStr);

                countDBArray = result.rows;
                $ScriptLog.Log(8, '获得数据' + JSON.stringify(countDBArray));
            })
            var count = {}; // 临时对象 存储数据
            countDBArray.forEach(function (item){
                // 如果该名称已经存在，数量加1，否则初始化为1
                if (count[item.name]) {
                    count[item.name]++;
                } else {
                    count[item.name] = 1;
                }
            })

            for (var key in count) {
                if (count.hasOwnProperty(key)) {
                    dbArray.push({
                        name: key,
                        value: count[key]
                    });
                }
            }

            var DBCount = {
                title: "数据库数量",
                data: dbArray
            };
            return [countHosts,DBCount];
        }

    };
    try {
        var params = JSON.parse($Params);
        qingteng.setParams(params);
        qingteng.getToken();

        qingteng.signature();
        return JSON.stringify(qingteng.getHostCountData());
        // return  qingteng.sha1("59080851823593e1a80b1733384227e003564e339b4a0f9982182e5865e3a7");
    } catch (err) {
        $ScriptLog.Log(9, '获得数据' + err);
        return $Result.error(err)
    }
}

executeJs();
